
<template>
  <el-dialog
    ref="refDlg"
    title="产品信息"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="600px"
    top="8vh"
    @close="closeDialog"
  >
    <table-box
      ref="refTable"
      v-loading="loading"
      table-size="mini"
      :table-config="tableConfig"
      :data="tableData"
      :table-height="200"
      show-index
    />
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { queryCrmByCode } from '@/api/autoDesignTask'
export default {
  name: 'FormDialog',
  components: { },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    code: {
      type: String,
      default: '',
      require: true
    }
  },
  data() {
    return {
      loading: false,
      tableData: [],
      tableConfig: {
        hideFuncBar: true,
        // 表格字段动态配置
        setting: [
          {
            prop: 'kjlProdSpace',
            label: '空间',
            minWidth: '140'
          },
          {
            prop: 'partNumber',
            label: '产品柜号',
            minWidth: '140'
          }, {
            prop: 'kjlProdType',
            label: '产品类型',
            minWidth: '140'
          }, {
            prop: 'kjlProdName',
            label: '产品名称',
            minWidth: '140'
          }, {
            prop: 'kjlProdColor',
            label: '产品颜色',
            minWidth: '140'
          }, {
            prop: 'todo',
            label: '柜体数量(个)',
            minWidth: '140'
          }, {
            prop: 'kjlPurchaseType',
            label: '采购类型(*)',
            minWidth: '130',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'top2-crm',
              dictTypeCode: 'CRM_ADS_PURCHASE_TYPE'
            }
          }, {
            prop: 'state',
            label: '产品是否终止',
            minWidth: '140',
            formatData: row => {
              const v = row.state
              if (v !== 'Normal') {
                return '是'
              } else if (v === 'Normal') {
                return '否'
              }
              return row.state
            }
          }

        ]
      }
    }
  },
  async created() {
    if (this.code) {
      this.loading = true
      queryCrmByCode(this.code).then(res => {
        if (res.success && res.data.records.length > 0) {
          this.tableData = res.data.records[0].orderItemList
        } else {
          this.$message.warning('无效单号，请检查')
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    }
  },
  methods: {
    closeDialog() {
      this.loading = false
      this.$emit('update:visible', false)
    }
  }
}
</script>
<style lang='scss' scoped>
/* @import url(); 引入css类 */

</style>
